// axios 封装
import axios from "axios";
import storage from "@/utils/storageHelper";

const request = axios.create({
  baseURL: "/api",
  timeout: 5000,
});

// 请求拦截器
request.interceptors.request.use(function (config) {
  const token = storage.localGet("token");

  if (token) {
    const Headers = {
      token,
    };
    config.headers = Headers;
  }

  return config;
});

// 响应拦截器
request.interceptors.response.use(
  (response) => {
    // 应写返回数据错误处理
    return response.data;
  },
  (err) => {
    // 应写请求出错统一处理
  }
);

export default request;
